package com.kiwilss.aliyundemo

import android.content.Intent
import android.os.Bundle
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import coil.load
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.kiwilss.aliyundemo.dylist.DYListActivity
import com.kiwilss.aliyundemo.dylist.VideoInfoBean
import kotlinx.android.synthetic.main.activity_recycler.*
import java.io.Serializable

/**
 * @author : Administrator
 * e-mail : kiwilss@163.com
 * time   : 2021/04/01
 *  desc   :
 */
class RecyclerActivty : AppCompatActivity(R.layout.activity_recycler) {
    val mAdapter by lazy { RecyclerAdapter() }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        rvRecyclerList.run {
            layoutManager = GridLayoutManager(this@RecyclerActivty,2)
            adapter = mAdapter
        }

        mAdapter.setList(GlobalConfig.getVideoList())
        mAdapter.setOnItemClickListener { adapter, view, position ->
            val data = mAdapter.data as ArrayList
            val intent = Intent(this,DYListActivity::class.java)
            intent.putExtra(GlobalConfig.POS,position)
            intent.putExtra(GlobalConfig.DATA,data)
            startActivity(intent)
        }

    }
}
//layoutResId: Int = R.layout.item_recycler
class RecyclerAdapter(): BaseQuickAdapter<VideoInfoBean, BaseViewHolder>(R.layout.item_recycler) {
    override fun convert(holder: BaseViewHolder, item: VideoInfoBean) {
        val ivPic = holder.getView<ImageView>(R.id.ivItemRecyclerPic)
        ivPic.load(item.cover)
        holder.setText(R.id.tvItemRecyclerTitle,item.title)
    }
}